<?php
class filemanager_model extends CI_Model
{
	function __construct()
	{
		 parent::__construct();
	}
	
	function getAllFile($num,$offset)
	{
		 $this->db->order_by('id','DESC');
		 $query = $this->db->get('filedata',$num,$offset);
		 return $query->result();
	}
	function getNumFile()
	{
		 $query = $this->db->get('filedata');
		 return $query->num_rows();
	} 
	
	function upload()
	{
		$this->load->library('upload_library');
		$size = $_FILES["filedata"]["size"];
		if($size > 0)
		{
			$filedata = $this->upload_library->uploadfile();
			if($filedata!='')
			{
				$file = explode('*',$filedata);
				$url = $file[0];
				$size = $file[1];
				$ext = $file[2];
				$data = array(
				  'name' => $file[3],
				  'url' => $url,
				  'size' => $size,
				  'ext' => $ext
				);
				$this->db->insert('filedata',$data);
				return $url;
			}
		}
		else
		{
		  return '';
		}
	}     
}
?>
